<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-body">
                    <form id="admin_rolelist_add_dialog_form">
                        <input type="hidden" name="id" value="{$info.roleid}"/>
                        <table class="table">
                            <tr>
                                <td width="100">角色名称：</td>
                                <td >
                                    <input id="admin_rolelist_add_dialog_form_name"
                                                                           type="text" name="info[rolename]"
                                                                           style="width:180px;height:26px" value="{$info.rolename}"/>
                                </td>
                                <td>
                                    <div id="admin_rolelist_add_dialog_form_nameTip"></div>
                                </td>
                            </tr>
                            <tr>
                                <td>角色描述：</td>
                                <td colspan="2"><textarea name="info[description]" style="width:90%;height:60px;font-size:12px">{$info.description}</textarea></td>
                            </tr>
                            <tr>
                                <td>是否启用：</td>
                                <td colspan="2">
                                    <label><input type="radio" name="info[disabled]" value="0"  <eq name="info.disabled" value="0">checked</eq>/>启用</label>
                                    <label><input type="radio" name="info[disabled]" value="1" <eq name="info.disabled" value="1">checked</eq>/>禁止</label>
                                </td>
                            </tr>
                            <tr>
                                <td>排序：</td>
                                <td colspan="2" style="height: 40px;"><input type="text" name="info[listorder]"
                                                       style="width:40px;height:22px"  value="{$info.listorder}"/></td>
                            </tr>
                        </table>
                        <div class="box-footer" >
                            <span class="input-group-btn">
                                <button class="btn btn-danger pull-left" type="button" id="close-dialog">取消</button>
                                <button class="btn btn-primary pull-right" type="button" id='form_submit' >提交</button>
                            </span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    $(function () {
        $('#form_submit').click(function () {
            $('#admin_rolelist_add_dialog_form').submit();
        });
        $.formValidator.initConfig({
            formID: "admin_rolelist_add_dialog_form",
            onError: function (msg) {
            },
            onSuccess: adminRolelistAddDialogFormSubmit,
            submitAfterAjaxPrompt: '有数据正在异步验证，请稍等...',
            inIframe: true
        });
        $("#admin_rolelist_add_dialog_form_name").formValidator({
            onShow: "请输入角色名称",
            onFocus: "角色名称不能为空"
        }).inputValidator({min: 1, max: 999, onError: "角色名称不能为空"}).ajaxValidator({
            type: "post",
            url: "{:U('Admin/public_checkRoleName')}",
            data: {
                id: '{$info.roleid}',
                rolename: function () {
                    return $("#admin_rolelist_add_dialog_form_name").val()
                }
            },
            datatype: "json",
            async: 'false',
            success: function (data) {
                var json = $.parseJSON(data);
                return json.status == 1 ? false : true;
            },
            onError: "角色名称已存在",
            onWait: "请稍候..."
        });
    })
    function adminRolelistAddDialogFormSubmit() {
        $.post("{:U('Admin/roleAdd')}", $("#admin_rolelist_add_dialog_form").serialize(), function (res) {
            if (!res.status) {
                $.messager.alert('提示信息', res.info, 'error');
            } else {
                $.messager.alert('提示信息', res.info, 'info');
                dialog.get('dialogPage').close().remove();
                reloadContent();
            }
        })
    }
</script>